#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int countHillValley(vector<int>& nums) {
        int left = 0, mid = 0;
        int res = 0;
        for (int right = 1; right < nums.size(); right++)
        {
            if (nums[right] == nums[right - 1])
                continue;
            if (left != mid)
            {
                if (nums[mid] > nums[left] && nums[mid] > nums[right])
                    ++res;
                else if (nums[mid] < nums[left] && nums[mid] < nums[right])
                    ++res;
            }
            left = mid;
            mid = right;
        }
        return res;
    }
};